package edu.auctionmart



import edu.auctionmart.Location;
import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Location)
class LocationTests {

    void testLocation() {
       Location testLocation = new Location(name: "Russell Gillen", addressLine: "50 USM Street", zipCode: "04103", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == false)
	   
	   testLocation = new Location(name: "Russell Gillen", addressLine: "50 USM Street", zipCode: "041031111", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == false)

	   //null name should have errors
	   testLocation = new Location(name: null, addressLine: "50 USM Street", zipCode: "04103", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
	   
	   //null address should have errors
	   testLocation = new Location(name: "Russell Gillen", addressLine: null, zipCode: "04103", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
	   
	   //malformed zipcode
	   testLocation = new Location(name: "Russell Gillen", addressLine: "50 USM Street", zipCode: "403", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
	   
	   //malformed zipcode
	   testLocation = new Location(name: "Russell Gillen", addressLine: "50 USM Street", zipCode: "4d03", town: "Portland", state: "ME")
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
	   
	   //null town should have errors
	   testLocation = new Location(name: 'Russell Gillen', addressLine: '50 USM Street', zipCode: "04103", town: null, state: 'ME')
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
	   
	   //State not in list should have errors
	   testLocation = new Location(name: 'Russell Gillen', addressLine: '50 USM Street', zipCode: "04103", town: 'Portland', state: 'Russell')
	   testLocation.validate()
	   assert(testLocation.hasErrors() == true)
    }
}
